﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TextAnalytics.Views
{
    /// <summary>
    /// Interaction logic for FileView.xaml
    /// </summary>
    public partial class FileView : UserControl, INotifyPropertyChanged
    {
        public FileView()
        {
            InitializeComponent();
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate(object sender, PropertyChangedEventArgs args) { };

        private void ProjectService_DidSelectFile(ProjectService projectService, SelectFileEventArgs args)
        {
            var textContent = projectService.GetSelectedFileContent();
            if (string.IsNullOrEmpty(textContent)) return;

            var flowDocument = new FlowDocument();
            
            var paragraph = new Paragraph();
            var run = new Run();
            run.Text = textContent;
            run.TextEffects.Add(new TextEffect() { Foreground = Brushes.Red});
            paragraph.Inlines.Add(run);
            var doc = new FlowDocument();
            doc.Blocks.Add(paragraph);
            TextBox.Document = doc;
        }

        private void FileView_Loaded(object sender, RoutedEventArgs e)
        {
            ProjectService.Default.DidSelectFile += ProjectService_DidSelectFile;
        }
    }
}
